//
//  MyRedPacket.m
//  cooba-iOS
//
//  Created by 郭四虎 on 16/8/26.
//  Copyright © 2016年 YouKu. All rights reserved.
//

#import "MyRedPacket.h"

@implementation MyRedPacket

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

+ (void)haveRedPacket:(void(^)(BOOL,NSString *firstT,NSString *lastT))back
{
    [MyAFN GET:SHOWPACKET success:^(NSDictionary *responseObj) {
        
        if ([[responseObj objectForKey:@"status"]integerValue]) {
            
            back(YES,[responseObj objectForKey:@"firstTime"],[responseObj objectForKey:@"lastTime"]);
        }else{
            back(NO,nil,nil);
        }
    } error:^(NSError *error) {
        
        back(NO,nil,nil);
    } fromController:nil];
}

+ (void)getRedPacket:(void(^)(BOOL,MyRedPacket *rp))back
{
    
    NSDictionary *parameter = @{@"user_id":[Myuser sharedUser].login_id};
    [MyAFN POST:GETPACKET parameters:parameter block:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        NSLog(@"%@",dic);
        if ([[dic objectForKey:@"status"]integerValue]){
        
            MyRedPacket *rp = [[MyRedPacket alloc]init];
            [rp setValuesForKeysWithDictionary:dic];
            back(YES,rp);
        }else{
            MyRedPacket *rp = [[MyRedPacket alloc]init];
            [rp setValuesForKeysWithDictionary:dic];
            back(NO,rp);
        }
    } error:^(NSError *error) {
        
    } fromController:nil];
}

+ (void)myWallet:(void(^)(BOOL,NSDictionary *))back vc:(UIViewController *)vc
{
    NSDictionary *parameter = @{@"user_id":[Myuser sharedUser].login_id};
    [MyAFN POST:MYPACKET parameters:parameter block:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        if ([[dic objectForKey:@"status"]integerValue]){
            
            back(YES,dic);
        }else{
            back(NO,dic);
        }
    } error:^(NSError *error) {
        
    } fromController:vc];
}

+ (void)reflectPacket:(NSString *)money name:(NSString *)name back:(void(^)(BOOL,NSDictionary *))back vc:(UIViewController *)vc
{
    NSDictionary *parameter = @{@"user_id":[Myuser sharedUser].login_id,@"money":money,@"name":name};
    [MyAFN POST:REFLECTPACKET parameters:parameter block:^(id responseObject) {
        
        NSDictionary *dic = responseObject;
        if ([[dic objectForKey:@"status"]integerValue]){
            
            back(YES,dic);
        }else{
            back(NO,dic);
        }
    } error:^(NSError *error) {
        
    } fromController:vc];
}

+ (void)redPacketRecord:(void(^)(NSDictionary *))back vc:(UIViewController *)vc nextKey:(NSInteger)nextKey
{
    NSDictionary *parameter = @{@"user_id":[Myuser sharedUser].login_id,@"next_key":@(nextKey),@"page_size":@"10"};
    [MyAFN POST:PACKETRECORD parameters:parameter block:^(id responseObject) {
        
        back(responseObject);
    } error:^(NSError *error) {
        
    } fromController:vc];
}

+ (void)reflectRecord:(void(^)(NSDictionary *))back vc:(UIViewController *)vc nextKey:(NSInteger)nextKey
{
    NSDictionary *parameter = @{@"user_id":[Myuser sharedUser].login_id};
    [MyAFN POST:REFLECTRECORD parameters:parameter block:^(id responseObject) {
        
        back(responseObject);
    } error:^(NSError *error) {
        
    } fromController:vc];
}

@end
